tools = {
    webmaster_path  :   'webmaster',
    web_site        :   'http://mob01.odingweb.com/',
    validate:function(form,success_fn,fail_fn){
        var url=$('input[name="action"]').val();
        !url && alert('请填写action隐藏域');
        form.submit(function(){return false;});
        form.validate({
            onfocusout  : false,
            onkeyup     : false,
            'submitHandler': function () {
                var oBtn=$('input:submit,button:submit');
                oBtn.attr('disabled','disabled');
                $.post(url, form.serialize(), function (data) {
                    if (data.ret == 1) {
                        success_fn && success_fn(data);
                    } else {
                        fail_fn && fail_fn(data);
                        oBtn && oBtn.attr('disabled', false);
                    }
                }, 'json');
            },
            showErrors: function(errorMap, errorList) {
                var msg = "";
                $(errorList).each(function(k,v){
                    msg+= v.message+"\n";
                });
                if(msg!=""){
                    alert(msg);
                }
            }
        });
    },
    show_mask: function() { //生成遮罩层
        var oDiv = document.createElement('div');
        $(oDiv).css({
            'left': 0,
            'top': 0,
            'width': $(window).width(),
            'height': $(window).height(),
            'position': 'fixed',
            'z-index': 9999,
            'background': 'rgba(0,0,0,0.7)'
        });
        $(oDiv).attr('id', 'mask');
        $(oDiv).addClass('move');
        return oDiv;
    },
    search_event:function(){
        $('.search_section .s_2').click(function(){
            var keyword=$('input[name="keyword"]').val();
            window.location.href = '/home/product_list/?keyword='+keyword;
        })
    },
    alert:function(msg,fn,type){
        var html = '';
        html += '<div class="alert_frame">';
        html += '<div class="title_frame"><span class="title_item">信息</span><span class="close_item hand">x</span></div>';
        html += '<div class="content">' + msg + '</div>';
        html += '<div class="btn_frame clean">';
        html += '<div class="line">';
        if (type) {
            html += '<span class="btn_1 hand">取消</span>';
        }
            html += '<span class="btn_0 hand">确定</span>';
        html += '</div>';
        html += '</div>';
        html += '</div>';
        var oDiv = tools.show_mask();
        if (!$('#mask').length) {
            $('body').append(oDiv);
            $('#mask').append(html);
            $('#mask').fadeIn('slow');
            $('#mask .alert_frame').fadeIn('slow');
            if (!type) {
                $('.alert_frame .btn_0,.alert_frame .close_item').click(function() {
                    if (fn) {
                        fn();
                        $('#mask').remove();
                    } else {
                        $('#mask').remove();
                    }
                });
            } else {
                $('.alert_frame .btn_1,.alert_frame .close_item').click(function() {
                    $('#mask').remove();
                });
                $('.alert_frame .btn_0').click(function() {
                    fn();
                    $('#mask').remove();
                });
            }
        }
    },
    back_event: function () {
        $('.back').click(function(){
            window.history.back(-1);
        });
    },
    confirm:function(){

    },
    scroll_event:function(){
        $(window).load(function(){
            //var sc =new IScroll({wrapper: $('#main_content'),scroller: $('#scroller'),bounce:false});
        });
    },
    logout:function(){
        $('#header_1 .list').eq(1).click(function(){
            window.location.href = '/login/logout/';
        });
    }
}
function startMove(obj,json,times,fx,fn,fnMove){
	var iCur = {};
	for(var attr in json){
		if(attr == 'opacity'){
			iCur[attr] = Math.round(getStyle(obj,attr)*100);
		}
		else{
			iCur[attr] = parseInt(getStyle(obj,attr));
		}
	}
	var startTime = now();
	clearInterval(obj.timer);
	obj.timer = setInterval(function(){
		var changeTime = now();
		var scale = 1 - Math.max(0,(startTime - changeTime + times)/times);
		if(fnMove){
			fnMove(scale);
		}
		for(var attr in json){	                
			var value = Tween[fx](scale*times, iCur[attr] , json[attr] - iCur[attr] , times );
			if(attr == 'opacity'){
				obj.style.filter = 'alpha(opacity='+ value +')';
				obj.style.opacity = value/100;
			} else {
				obj.style[attr] = value + 'px';
			}
			if(scale==1){
				clearInterval(obj.timer);
				if(fn){
					fn.call(obj);
				}
			}
		}
	},13);
	function now(){
		return Date.now();
	}
	
}
function getStyle(obj, attr){
	if(obj.currentStyle){
		return obj.currentStyle[attr];
	} else {
		return getComputedStyle(obj, false)[attr];
	}
}

var Tween = {
	linear: function (t, b, c, d){
		return c*t/d + b;
	},
	easeIn: function(t, b, c, d){
		return c*(t/=d)*t + b;
	},
	easeOut: function(t, b, c, d){
		return -c *(t/=d)*(t-2) + b;
	},
	easeBoth: function(t, b, c, d){
		if ((t/=d/2) < 1) {
			return c/2*t*t + b;
		}
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInStrong: function(t, b, c, d){
		return c*(t/=d)*t*t*t + b;
	},
	easeOutStrong: function(t, b, c, d){
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeBothStrong: function(t, b, c, d){
		if ((t/=d/2) < 1) {
			return c/2*t*t*t*t + b;
		}
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	}
}

